<% content_for :scripts do %>
  <script type="text/javascript">
    <% if current_user && !@user_liked_reply_ids.blank? %>
    Topics.user_liked_reply_ids = [<%= @user_liked_reply_ids.join(",") %>];
    <% end %>
    $(document).ready(function(){
      <% if admin? %>
        $("#replies .reply a.edit").css('display','inline-block');
      <% elsif current_user %>
        $("#replies .reply a.edit[data-uid='<%= current_user.id %>']").css('display','inline-block');
      <% end %>
    })
  </script>
<% end %>

<div class="row">
  <div class="col-md-9">
    <div class="topic-detail panel panel-default">
      <%= render partial: "topics/topic_info", locals: { topic: @topic } %>

      <div class="panel-body markdown">
        <%= raw SiteConfig.before_topic_html %>

        <article>
          <%= raw @topic.body_html %>
        </article>


        <%= raw SiteConfig.after_topic_html %>
        <%= social_share_button_tag h("#{@topic.title} via: @#{Setting.twitter_id} ") %>
      </div>

      <% if @topic.excellent? %>
        <div class="label-awesome">
          <i class="fa fa-diamond awesome"></i> 本帖已被设为精华帖！
          <% if admin? %>
          <div class="pull-right">
            <%= link_to icon_tag("close"), unsuggest_topic_path(@topic.id), data: { confirm: "确定要取消么？", method: "delete" } %>
          </div>
          <% end %>
        </div>
      <% end %>

      <div class="panel-footer clearfix">
        <%= render "buttons" %>
      </div>
    </div>

    <%= render partial: "ban_reason" %>

  <% if @replies.blank? %>
    <div class="no-result">
      <%= t("topics.no_replies") %>
    </div>
    <% else %>
    <div id="replies" class="panel panel-default" data-last-floor="<%= @replies.count %>">
      <div class="total panel-heading">
        共收到 <b><%= @topic.replies_count %></b> 条回复
      </div>
      <div class="items panel-body">
        <%= cache([@topic, "raw:#{@show_raw}"]) do %>
          <%= render partial: "replies/reply", collection: @replies %>
        <% end %>
      </div>
    </div>
  <% end %>

  <% if current_user %>
    <div id="reply" class="panel panel-default">
      <div class="panel-heading">回帖</div>
      <div class="panel-body">
      <% if can? :create, Reply %>

        <%= render "editor_toolbar" %>
        <%= form_for(Reply.new, remote: true, url: topic_replies_path(@topic)) do |f| %>

          <div class="form-group">
            <%= f.text_area :body, class: "topic-editor form-control", rows: "4", tabindex: "1" %>
          </div>
          <div class="submit-buttons">
            <button type="submit" id="reply-button" class="btn btn-primary" tabindex="2"><%= t("topics.submit_reply")%></button>
            <span class="help-inline" style="padding-left: 5px;" title="或者 Ctrl + Enter"><kbd>Command</kbd> + <kbd>Enter</kbd></span>

            <div class="pull-right"><a href="/markdown" target="_blank">排版说明</a></div>
          </div>
        <% end %>
      <% else %>
        <div class="alert alert-info">
          当前设置新手用户不能在 22:00 ~ 9:00 发帖。
        </div>
      <% end %>
      </div>
    </div>
  <% else %>
    <div class="panel panel-default">
      <div class="panel-body">
        <%= render partial: "topics/translation/need_login_to_reply" %>
      </div>
    </div>
  <% end %>
  </div>

<% if !mobile? %>
  <div class="sidebar hidden-mobile col-md-3">
    <%= render 'topic_sidebar' %>
  </div>
<% end %>
</div>
